<template>
  <div>
    <div class="banner">
      <van-swipe class="my-swipe" :autoplay="3000">
        <van-swipe-item v-for="image in imgList" :key="image.link_content">
          <img class="imgSw" v-lazy="image.banner_img" />
        </van-swipe-item>
      </van-swipe>
    </div>
    <div class="tag">
      <ul>
        <li @click="$router.push('/course')">
          <van-icon name="chat-o" size="1rem" />
          <span>特色课</span>
        </li>
        <li class="middle">
          <van-icon name="chat-o" size="1rem" />
          <span>一对一辅导</span>
        </li>
        <li @click="$router.push('/calend')">
          <van-icon name="chat-o" size="1rem" />
          <span>学习日历</span>
        </li>
      </ul>
    </div>
    <div
      class="kc"
      v-for="(card, index) in cardList"
      :key="card.channel_info.id"
    >
      <p class="title">{{ card.channel_info.name }}</p>
      <div class="twoCard" v-if="index == 1">
        <div class="card" v-for="cardChild in card.list" :key="cardChild.id">
          <div class="cardtitle">{{ cardChild.title }}</div>
          <div class="cardDian">共点击量</div>
          <div data-v-321e04ce="">
            <div class="flex">
              <div class="img">
                <img alt="" :src="cardChild.cover_img" />
              </div>
              <div class="right">
                <p data-v-321e04ce="">12345678</p>
              </div>
            </div>
          </div>
          <div class="itemDl flex">
            <div data-v-321e04ce="">274人报名</div>
            <div class="price">
              <van-icon name="points" /> {{ cardChild.price }}
            </div>
          </div>
        </div>
      </div>
      <div class="count" v-else>
        <div
          class="card flex"
          v-for="cardChild in card.list"
          :key="cardChild.teacher_id"
          @click="$router.push('/teacherDetail')"
        >
          <div class="hearImg">
            <img :src="cardChild.teacher_avatar" alt="" />
          </div>
          <div class="rightCount">
            <p>{{ cardChild.teacher_name }}</p>
            <span>{{ cardChild.introduction }}</span>
          </div>
        </div>
      </div>
    </div>

    <div class="fixBox">
      <van-icon class="iconBox" name="envelop-o" size="1rem" />
    </div>
  </div>
</template>

<script>
import { banner, cartList } from "../request/http";
export default {
  data() {
    return {
      imgList: [],
      cardList: [],
    };
  },
  methods: {
    init() {
      banner().then((res) => {
        if ((res.data.code = 200)) {
          this.imgList = res.data.data;
        } else {
          return;
        }
      });
      cartList().then((res) => {
        console.log(res);
        if ((res.data.code = 200)) {
          this.cardList = res.data.data;
        } else {
          return;
        }
      });
    },
  },
  mounted() {
    this.$toast.loading({
      message: "加载中...",
      forbidClick: true,
      loadingType: "spinner",
    });
    this.init();
  },
};
</script>

<style scoped lang="scss">
.banner {
  overflow: hidden;
  width: 100%;
  height: 0;
  padding-bottom: 30%;
}
.imgSw {
  width: 100%;
  height: 100%;
}
.tag {
  width: 100%;
  height: 2.747rem;
  margin: 0 auto;
  position: relative;
  top: -0.667rem;
  margin-bottom: -0.533rem;
  display: flex;
  justify-content: center;
  align-items: center;
  ul {
    width: 90%;
    height: 2.747rem;
    display: flex;
    color: #8c8c8c;
    border-radius: 0.267rem;
    text-align: center;
    justify-content: space-between;
    li {
      width: 2.747rem;
      height: 2.747rem;
      background-color: #fff;
      border-radius: 0.267rem;
      display: flex;
      flex-direction: column;
      text-align: center;
      justify-content: space-around;
    }
    // .middle {
    //   margin: 0 14.92px;
    // }
  }
}
.kc {
  width: 95%;
  margin: 0 auto;
  .title {
    border-left: 0.08rem solid red;
    padding-left: 0.267rem;
    font-size: 0.453rem;
  }
  .flex {
    display: flex;
  }
  .card {
    box-sizing: border-box;
    width: 100%;
    padding: 0.267rem 0.427rem;
    overflow: hidden;
    color: #323233;
    font-size: 0.373rem;
    line-height: 0.64rem;
    background-color: #fff;
    margin-bottom: 0.2rem;
    .hearImg {
      width: 1rem;
      height: 1rem;
      border-radius: 50%;
      margin: auto 0;
      overflow: hidden;
      margin-right: 0.427rem;
    }
    img {
      width: 1rem;
      height: 1rem;
    }
    p {
      color: #323233;
      font-size: 0.373rem;
    }
    span {
      font-size: 0.32rem;
      color: #999;
    }
  }
  .itemDl {
    justify-content: space-between;
  }
  .price {
    font-size: 0.453rem;
    color: #ff3c00;
    font-weight: 500;
  }
}
.fixBox {
  background: #007aff;
  border-radius: 100%;
  text-align: center;
  color: #fff;
  position: fixed;
  bottom: 2.133rem;
  right: 0.267rem;
  width: 1.6rem;
  height: 1.6rem;
  z-index: 99999999;
  .iconBox {
    line-height: 1.6rem;
  }
}
</style>